home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Sets / BCSet.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  2.7 KB  |  116 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCSet.h
  5. //
  6. //  This file contains the declaration of the set abstract base class
  7. //  and its iterators.
  8.  
  9. #ifndef BCSET_H
  10. #define BCSET_H 1
  11.  
  12. #include "BCType.h"
  13.  
  14. template<class Item>
  15. class BC_TSetActiveIterator;
  16.  
  17. template<class Item>
  18. class BC_TSetPassiveIterator;
  19.   
  20. template<class Item, class Value, class Structure>
  21. class BC_TTablePersist;  
  22.  
  23. // Set abstract base class
  24.  
  25. template<class Item>
  26. class BC_TSet {
  27. public:
  28.  
  29.   BC_TSet();
  30.   BC_TSet(const BC_TSet<Item>&);
  31.   virtual ~BC_TSet();
  32.  
  33.   virtual BC_TSet<Item>& operator=(const BC_TSet<Item>&);
  34.   virtual BC_Boolean operator==(const BC_TSet<Item>&) const;
  35.   BC_Boolean operator!=(const BC_TSet<Item>&) const;
  36.  
  37.   virtual void SetHashFunction(BC_Index (*)(const Item&)) = 0;
  38.   virtual void Clear() = 0;
  39.   virtual BC_Boolean Add(const Item&) = 0;
  40.   virtual BC_Boolean Remove(const Item& at) = 0;
  41.   virtual void Union(const BC_TSet<Item>&);
  42.   virtual void Intersection(const BC_TSet<Item>&);
  43.   virtual void Difference(const BC_TSet<Item>&);
  44.  
  45.   virtual BC_Index Extent() const = 0;
  46.   virtual BC_Boolean IsEmpty() const = 0;
  47.   virtual BC_Boolean IsMember(const Item&) const = 0;
  48.   virtual BC_Boolean IsSubset(const BC_TSet<Item>&) const;
  49.   virtual BC_Boolean IsProperSubset(const BC_TSet<Item>&) const;
  50.  
  51. protected:
  52.  
  53.   virtual void Purge() = 0;
  54.   virtual BC_Boolean Attach(const Item&, const BC_Boolean&);
  55.   virtual BC_Boolean Attach(const Item&) = 0;
  56.   virtual BC_Boolean Detach(const Item&) = 0;
  57.   virtual BC_Index Cardinality() const = 0;
  58.   virtual BC_Index NumberOfBuckets() const = 0;
  59.   virtual BC_Index Length(BC_Index bucket) const = 0;
  60.   virtual BC_Boolean Exists(const Item&) const = 0;
  61.   virtual const Item& ItemAt(BC_Index bucket, BC_Index index) const = 0;
  62.   
  63.   virtual void Lock();
  64.   virtual void Unlock();
  65.   
  66. private:
  67.  
  68.   friend class BC_TSetActiveIterator<Item>;
  69.   friend class BC_TSetPassiveIterator<Item>;
  70.   
  71.   friend class BC_TTablePersist<Item, BC_Boolean, BC_TSet<Item> >;
  72.  
  73. };
  74.  
  75. // Set iterators
  76.  
  77. template <class Item>
  78. class BC_TSetActiveIterator {
  79. public:
  80.  
  81.   BC_TSetActiveIterator(const BC_TSet<Item>&);
  82.   ~BC_TSetActiveIterator();
  83.   
  84.   void Reset();
  85.   BC_Boolean Next();
  86.  
  87.   BC_Boolean IsDone() const;
  88.   const Item* CurrentItem() const;
  89.   Item* CurrentItem();
  90.   
  91. protected:
  92.  
  93.   const BC_TSet<Item>& fSet;
  94.   BC_ExtendedIndex fBucketIndex;
  95.   BC_ExtendedIndex fIndex;
  96.   
  97. };
  98.  
  99. template <class Item>
  100. class BC_TSetPassiveIterator {
  101. public:
  102.  
  103.   BC_TSetPassiveIterator(const BC_TSet<Item>&);
  104.   ~BC_TSetPassiveIterator();
  105.   
  106.   BC_Boolean Apply(BC_Boolean (*)(const Item&));
  107.   BC_Boolean Apply(BC_Boolean (*)(Item&));
  108.   
  109. protected:
  110.  
  111.   const BC_TSet<Item>& fSet;
  112.  
  113. };
  114.  
  115. #endif
  116.